package book_management.book;



import java.util.ArrayList;
import java.util.List;

/**
 * 书架
 * @author yuisama
 * @date 2022/05/08 17:33
 **/
public class BookList {
    // 书架就是保存书籍的，书本的个数不确定，要么用动态数组，要么使用链表
    private List<Book> books = new ArrayList<>();
    // 保存当前书架上所有的书籍名称，以后的操作就是根据这个书籍的名称来查找具体的Book对象，
    // 一一对应的映射关系
    private List<String> booksName = new ArrayList<>();

    public BookList() {
        // 产生一个书架对象时，默认上架的四本书籍
        books.add(new Book("三国演义","罗贯中",66.6,"小说"));
        books.add(new Book("水浒传","施耐庵",55.6,"小说"));
        books.add(new Book("西游记","吴承恩",44.6,"小说"));
        books.add(new Book("红楼梦","曹雪芹&未知",88.6,"小说"));
        // 将当前这四本书的书名也添加到booksName列表中
        booksName.add("三国演义");
        booksName.add("水浒传");
        booksName.add("西游记");
        booksName.add("红楼梦");
    }

    public void listBooks() {
        for (Book book : books) {
            System.out.println(book);
        }
    }

    public boolean contains(String booksName) {
        // 遍历booksName这个列表即可
        for (String str : this.booksName) {
            if (str.equals(booksName)) {
                return true;
            }
        }
        return false;
    }

    public void addNewBook(String booksName, String author, String type, double price) {
        Book book = new Book(booksName,author,price,type);
        this.books.add(book);
        this.booksName.add(booksName);
    }
}